<?php

namespace App\Listeners;

use App\Events\ApkUploaded;
use App\Models\Game\Center\Apk;
use Illuminate\Support\Facades\Storage;

class MakeApkDownloadJson
{
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  ApkUploaded  $event
     * @return void
     */
    public function handle(ApkUploaded $event)
    {
        $apks = Apk::whereStatus(Apk::STATUS_UPLOAD)->get();
        $data = [];
        foreach ($apks as $apk) {
            $data[$apk->source] = $apk->download_url .'?t='. $apk->updated_at->timestamp;
        }
        $jsonString = json_encode($data);
        Storage::disk('static')->put('apk.json', $jsonString);
        Storage::disk('oss')->put('apk.json', $jsonString);
    }
}
